import javax.imageio.ImageIO;
import javax.swing.*;
import java.awt.*;
import java.awt.image.BufferedImage;
import java.io.IOException;

public class ImageDemo extends JPanel {
    @Override
    public void paint(Graphics g) {
        super.paint(g);
        //画小飞机
      paintAirPlane(g);
    }
    private void paintAirPlane(Graphics g) {
        BufferedImage img = null;
        try {
            img = ImageIO.read(ImageDemo.class.getResourceAsStream("pic/airplane.png"));
        } catch (IOException e) {
            e.printStackTrace();
        }
        g.drawImage(img,100,100,this);
    }

    public static void main(String[] args) {
        //创建窗口对象
        JFrame win = new JFrame();
        //设置窗口标题
        win.setTitle("飞机大战");
        //设置窗口大小
        win.setSize(400,650);
        //居中显示
        win.setLocationRelativeTo(null);
        //设置窗口没有外边框
        //win.setUndecorated(true);
        //显示窗口
        win.setVisible(true);
        //设置窗口默认关闭选项
        win.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        //将画板添加到窗口上
        ImageDemo panel = new ImageDemo();
        win.add(panel);


    }
}
